home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / init.d / bluetooth < prev    next >
Encoding:
Text File  |  2007-03-30  |  6.4 KB  |  281 lines

  1. #! /bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: bluetooth
  4. # Required-Start:    $local_fs $syslog $remote_fs
  5. # Required-Stop:     $local_fs $syslog $remote_fs
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Start bluetooth daemons
  9. ### END INIT INFO
  10. #
  11. # bluez-utils    Bluetooth subsystem starting and stopping
  12. #
  13. # originally from bluez's scripts/bluetooth.init
  14. #
  15. # Edd Dumbill <ejad@debian.org>
  16. # LSB 3.0 compilance and enhancements  by Filippo Giunchedi <filippo@debian.org>
  17. #
  18. # startup control over dund and pand can be changed by editing
  19. # /etc/default/bluez-utils
  20.  
  21. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  22. DESC="Bluetooth services"
  23.  
  24. HCID=/usr/sbin/hcid
  25. HCIATTACH=/usr/sbin/hciattach
  26. HCID_NAME=hcid
  27. HCID_OPTIONS="-x -s"
  28.  
  29. HID2HCI=/usr/sbin/hid2hci
  30.  
  31. UART_CONF=/etc/bluetooth/uart
  32.  
  33. RFCOMM=/usr/bin/rfcomm
  34. RFCOMM_NAME=rfcomm
  35. RFCOMM_CONF=/etc/bluetooth/rfcomm.conf
  36.  
  37. SDPTOOL=/usr/bin/sdptool
  38.  
  39. DUND_DAEMON=/usr/bin/dund
  40. DUND_NAME=dund
  41. PAND_DAEMON=/usr/bin/pand
  42. PAND_NAME=pand
  43. HIDD_DAEMON=/usr/bin/hidd
  44. HIDD_NAME=hidd
  45.  
  46. DUND_ENABLED=0
  47. PAND_ENABLED=0
  48. HIDD_ENABLED=0
  49. DUND_OPTIONS=""
  50. PAND_OPTIONS=""
  51. HIDD_OPTIONS="--master --server"
  52.  
  53. test -f /etc/default/bluetooth && . /etc/default/bluetooth
  54. test -f /etc/default/rcS && . /etc/default/rcS
  55.  
  56. . /lib/lsb/init-functions
  57.  
  58. # test for essential daemons
  59. test -x $HCID || exit 0
  60. test -x $HCIATTACH || exit 0
  61. test -x $RFCOMM || exit 0
  62.  
  63. # disable nonessential daemons if not present
  64. if test "$DUND_ENABLED" != "0"; then
  65.     if ! test -f $DUND_DAEMON; then
  66.         DUND_ENABLED=0
  67.     fi
  68. fi
  69.  
  70. if test "$PAND_ENABLED" != "0"; then
  71.     if ! test -f $PAND_DAEMON; then
  72.         PAND_ENABLED=0
  73.     fi
  74. fi
  75.  
  76. if test "$HIDD_ENABLED" != "0"; then
  77.     if ! test -f $HIDD_DAEMON; then
  78.         HIDD_ENABLED=0
  79.     fi
  80. fi
  81.  
  82. set -e
  83.  
  84. run_sdptool()
  85. {
  86.     test -x $SDPTOOL || return 1 
  87.  
  88.     if ! test -z "$SDPTOOL_OPTIONS" ; then
  89.         oldifs="$IFS"
  90.         IFS=";"
  91.         for o in $SDPTOOL_OPTIONS ; do
  92.             #echo "execing $SDPTOOL $o"
  93.             IFS=" "
  94.             $SDPTOOL $o &>/dev/null
  95.         done
  96.         IFS="$oldifs"
  97.     fi
  98.  
  99. }
  100.  
  101. enable_hci_input()
  102. {
  103.        if [ "$VERBOSE" != no ]; then
  104.                log_success_msg "Switching on Bluetooth input devices..."
  105.                $HID2HCI --tohci
  106.        else
  107.                $HID2HCI --tohci >/dev/null 2>&1
  108.        fi
  109. }
  110.  
  111. disable_hci_input()
  112. {
  113.        if [ "$VERBOSE" != no ]; then
  114.                log_success_msg "Switching Bluetooth input devices back to HID mode..."
  115.                $HID2HCI --tohid
  116.        else
  117.                $HID2HCI --tohid >/dev/null 2>&1
  118.        fi
  119. }
  120.  
  121. start_pan()
  122. {
  123.     if test "$DUND_ENABLED" != "0"; then
  124.         start-stop-daemon --start --quiet --exec $DUND_DAEMON -- $DUND_OPTIONS
  125.         [ "$VERBOSE" != no ] && log_success_msg "Starting $DUND_NAME..."
  126.  
  127.     fi
  128.     if test "$PAND_ENABLED" != "0"; then
  129.         start-stop-daemon --start --quiet --exec $PAND_DAEMON -- $PAND_OPTIONS
  130.         [ "$VERBOSE" != no ] && log_success_msg "Starting $PAND_NAME..."
  131.     fi
  132. }
  133.  
  134.  
  135. stop_pan()
  136. {
  137.     if test "$DUND_ENABLED" != "0"; then
  138.         start-stop-daemon --stop --quiet --exec $DUND_DAEMON || true
  139.         [ "$VERBOSE" != no ] && log_success_msg "Stopping $DUND_NAME..."
  140.     fi
  141.     if test "$PAND_ENABLED" != "0"; then
  142.         start-stop-daemon --stop --quiet --exec $PAND_DAEMON || true
  143.         [ "$VERBOSE" != no ] && log_success_msg "Stopping $PAND_NAME..."
  144.     fi
  145. }
  146.  
  147. start_hid()
  148. {
  149.     if test "$HIDD_ENABLED" != "0"; then
  150.         start-stop-daemon --start --quiet --exec $HIDD_DAEMON -- $HIDD_OPTIONS
  151.         [ "$VERBOSE" != no ] && log_success_msg "Starting $HIDD_NAME..."
  152.     fi
  153. }
  154.  
  155. stop_hid()
  156. {
  157.     if test "$HIDD_ENABLED" != "0"; then
  158.         $HIDD_DAEMON --killall
  159.         start-stop-daemon --stop --quiet --exec $HIDD_DAEMON || true
  160.         [ "$VERBOSE" != no ] && log_success_msg "Stopping $HIDD_NAME..."
  161.     fi
  162. }
  163.  
  164. start_uarts()
  165. {
  166.     [ -f $HCIATTACH ] && [ -f $UART_CONF ] || return
  167.     grep -v '^#' $UART_CONF | while read i; do
  168.                if [ "$VERBOSE" != no ]; then
  169.                        $HCIATTACH $i
  170.                else
  171.                        $HCIATTACH $i >/dev/null 2>&1
  172.                fi
  173.     done
  174. }
  175.  
  176. stop_uarts()
  177. {
  178.     killall hciattach > /dev/null 2>&1 || true
  179. }
  180.  
  181. start_rfcomm()
  182. {
  183.     if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
  184.         # rfcomm must always succeed for now: users
  185.         # may not yet have an rfcomm-enabled kernel
  186.                 if [ "$VERBOSE" != no ]; then
  187.                        log_success_msg "Starting $RFCOMM_NAME..."
  188.                        $RFCOMM -f $RFCOMM_CONF bind all || true
  189.                 else
  190.                        $RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
  191.                 fi
  192.     fi
  193. }
  194.  
  195. stop_rfcomm()
  196. {
  197.     if [ -x $RFCOMM ] ; then
  198.                if [ "$VERBOSE" != no ]; then
  199.                        log_success_msg "Stopping $RFCOMM_NAME..."
  200.                        $RFCOMM unbind all || true
  201.                else
  202.                        $RFCOMM unbind all >/dev/null 2>&1 || true
  203.                fi
  204.     fi
  205. }
  206.  
  207. restart_rfcomm()
  208. {
  209.     if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
  210.                if [ "$VERBOSE" != no ]; then
  211.                        log_success_msg  "Restarting $RFCOMM_NAME..."
  212.                        $RFCOMM unbind all || true
  213.                        $RFCOMM -f $RFCOMM_CONF bind all || true
  214.                else
  215.                        $RFCOMM unbind all >/dev/null 2>&1|| true
  216.                        $RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
  217.                fi
  218.     fi
  219. }
  220.  
  221. case "$1" in
  222.   start)
  223.     log_daemon_msg "Starting $DESC"
  224.     
  225.     if test "$BLUETOOTH_ENABLED" == "0"; then
  226.         log_progress_msg "disabled. see /etc/default/bluetooth"
  227.         log_end_msg 0
  228.         exit 0
  229.     fi
  230.  
  231.     start-stop-daemon --start --quiet --exec $HCID -- $HCID_OPTIONS || true
  232.     log_progress_msg "hcid"
  233.     start_uarts || true
  234.     
  235.     start_hid || true
  236.     enable_hci_input || true
  237.     start_rfcomm || true
  238.     start_pan || true
  239.     log_end_msg 0
  240.     ;;
  241.   stop)
  242.     log_daemon_msg "Stopping $DESC"
  243.     stop_pan || true
  244.     stop_rfcomm || true
  245.     disable_hci_input || true
  246.     stop_hid || true
  247.     start-stop-daemon --stop --quiet --exec $HCID || true
  248.     log_progress_msg "$HCID_NAME"
  249.     stop_uarts || true
  250.     log_end_msg 0
  251.     ;;
  252.   restart|force-reload)
  253.     log_daemon_msg "Restarting $DESC"
  254.     stop_hid || true
  255.     stop_pan || true
  256.     start-stop-daemon --stop --quiet --exec $HCID || true
  257.     sleep 1
  258.     if test "$BLUETOOTH_ENABLED" == "0"; then
  259.         log_progress_msg "disabled. see /etc/default/bluetooth"
  260.         log_end_msg 0
  261.         exit 0
  262.     fi
  263.     start-stop-daemon --start --quiet --exec $HCID -- $HCID_OPTIONS || true
  264.     log_progress_msg "$HCID_NAME"
  265.     start_pan || true
  266.     start_hid || true
  267.     restart_rfcomm
  268.     log_end_msg 0
  269.     ;;
  270.   *)
  271.     N=/etc/init.d/bluetooth
  272.     # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  273.     echo "Usage: $N {start|stop|restart|force-reload}" >&2
  274.     exit 1
  275.     ;;
  276. esac
  277.  
  278. exit 0
  279.  
  280. # vim:noet
  281.